/**
 * 
 */

function _init(){

	var _seasonId = $('#seasonId').val();
	var _zoneId = $('#zoneId').val();
	var _schoolId = $('#schoolId').val();
	var _teamId = $('#teamId').val();
	var _cityId = $('#cityId').val();
	if(_seasonId != ''){
		//var _seasonValue = $('_season').next().find("li[value="+_seasonId+"]");
		$('#season_sel').attr('value',_seasonId);
		$('#season_sel').text($('#season_sel').next().find("li[value="+_seasonId+"]").text());
	}
	if(_zoneId != ''){
		//var _seasonValue = $('_season').next().find("li[value="+_seasonId+"]");
		checkCity(_zoneId);
		$('#zone_sel').attr('value',_zoneId);
		$('#zone_sel').text($('#zone_sel').next().find("li[value="+_zoneId+"]").text());
	}
	
	if(_cityId != ''){
		querySchool(_cityId);
		$('#city_sel').attr('value',_cityId);
		$('#city_sel').text($('#city_sel').next().find("li[value="+_cityId+"]").text());
	}
	if(_schoolId != ''){
		queryTeam(_schoolId);
		$('#school_sel').attr('value',_schoolId);
		$('#school_sel').text($('#school_sel').next().find("li[value="+_schoolId+"]").text());
	}
	
	if(_teamId != ''){
		$('#team_sel').attr('value',_teamId);
		$('#team_sel').text($('#team_sel').next().find("li[value="+_teamId+"]").text());
	}
	
}

var teamId="";

$(function(){
	_init();
		$('.selul li').hover(function(){$(this).addClass('hovon')},function(){$(this).removeClass('hovon')});
		$('.selul li').on('click',function(){
			$(this).parent().slideToggle('fast').parent().find('.sellight').text($(this).text())});
		$('.sellight').on('click',function(){$(this).next().slideToggle('fast')});
		
		$(".querySeasonId").click(function(){
			var seasonId=$(this).val();
			$('#season_sel').attr('value',seasonId);
		});
		
		$(".queryZoneId").click(function(e){
			var zoneId=$(this).val();
			$.ajax({
	            url: '/playerDate/queryCityByZoneId.yson',
	            type: 'post',
	            dataType: "json",
	            data: {zoneId: zoneId},
	            success: function (data) {
	                var citySelect = "";
	                $(data).each(function (i, obj) {
	                    citySelect +="<li id='cityLiId"+i+"' onclick='checkZone("+i+")' " +
	                    		     "onmousemove='mouseMoveZone("+i+")' onmouseout='mouseOutZone("+i+")' " +
	                    		     "value=" + obj.id + ">" + obj.name + "</li>";
	                    
	                    $('#city_sel').attr('value','');
	                    $('#city_sel').text('请选择');
	                    $('#school_sel').attr('value','');
	                    $('#school_sel').text('请选择');
	                    $('#team_sel').attr('value','');
	                    $('#team_sel').text('请选择');
	                });
	                $("#cityUi").empty().append(citySelect);
	                $('#zone_sel').attr('value',zoneId);
	            }
	        });
			
		});
		
		$("#dp-search").click(function(){
			//var season=$("#season_sel").text();
			//var zone = $("#zone_sel").text();
			//var city = $("#city_sel").text();
			//var school=$("#school_sel").text();
			
			var seasonId=$("#season_sel").attr('value');
			var zoneId = $("#zone_sel").attr('value');
			var cityId= $("#city_sel").attr('value');
			var schoolId=$("#school_sel").attr('value');
			var teamId=$("#team_sel").attr('value');
			if(seasonId==undefined){
				alert("请选择赛季");
				return false;
			}
			if(zoneId==undefined){
				alert("请选择赛区");
				return false;
			}
			if(cityId==""){
				alert("请选择城市");
				return false;
			}
			
			if(schoolId==""){
				alert("请选择学校");
				return false;
			}
			if(teamId==""){
				alert("请选择球队");
				return false;
				
			}else if(teamId!="" && teamId!=null){
				window.location.href = "/playerDate/personalDataList.html?teamId="+teamId
				+"&schoolId="+schoolId+"&cityId="+cityId+"&zoneId="+zoneId+"&seasonId="+seasonId;
			}
			
		});
		
		$(".queryPlayer").click(function(e){
			window.location.href = "/playerDate/personalDateHistoryList.html?id="+e.currentTarget.id;
		});
		
       $("#personal-Data").click(function(){
			
			window.location.href = "/playerDate/personalDataList.html";
			
		});
		
		$("#team-Data").click(function(){
			
			window.location.href = "/teamDate/teamDataList.html";
			
		});
		
	});


function checkCity(zoneId){
//	var zoneId=$(this).val();
	$.ajax({
        url: '/teamDate/queryCityByZoneId.yson',
        type: 'post',
        dataType: "json",
        async : false,
        data: {zoneId: zoneId},
        success: function (data) {
            var citySelect = "";
            $(data).each(function (i, obj) {
                citySelect +="<li id='cityLiId"+i+"' onclick='checkZone("+i+")' " +
                		     "onmousemove='mouseMoveZone("+i+")' onmouseout='mouseOutZone("+i+")' " +
                		     "value=" + obj.id + ">" + obj.name + "</li>";
                $('#city_sel').attr('value','');
                $('#city_sel').text('请选择');
                $('#school_sel').attr('value','');
                $('#school_sel').text('请选择');
                $('#team_sel').attr('value','');
                $('#team_sel').text('请选择');
            });
            $("#cityUi").empty().append(citySelect);
            $('#zone_sel').attr('value',zoneId);
        }
    });
}

function querySchool(cityId){
	$.ajax({
        url: '/playerDate/querySchoolByCityId.yson',
        type: 'post',
        dataType: "json",
        async : false,
        data: {cityId: cityId},
        success: function (data) {
            var schoolSelect = "";
            $(data).each(function (i, obj) {
            	schoolSelect +="<li id='schoolLiId"+i+"' onclick='checkTeam("+i+")' " +
                		     "onmousemove='mouseMoveCity("+i+")' onmouseout='mouseOutCity("+i+")' " +
                		     "value=" + obj.id + ">" + obj.name + "</li>";
            	
            	$('#school_sel').attr('value','');
                $('#school_sel').text('请选择');
                $('#team_sel').attr('value','');
                $('#team_sel').text('请选择');
            });
            $("#schoolUi").empty().append(schoolSelect);
            $('#city_sel').attr('value',cityId);
        }
    });
}



function queryTeam(schoolId){
	$.ajax({
        url: '/playerDate/queryTeamBySchoolId.yson',
        type: 'post',
        dataType: "json",
        async : false,
        data: {schoolId: schoolId},
        success: function (data) {
            var teamSelect = "";
            $(data).each(function (i, obj) {
            	teamSelect +="<li id='teamLiId"+i+"' onclick='checkPlayer("+i+")' " +
	   		     "onmousemove='mouseMoveTeam("+i+")' onmouseout='mouseOutTeam("+i+")' " +
	   		     "value=" + obj.id + ">" + obj.name + "</li>";
            	
            	 $('#team_sel').attr('value','');
                 $('#team_sel').text('请选择');
            });
            $("#teamUi").empty().append(teamSelect);
            $('#school_sel').attr('value',schoolId);
        }
    });
}



function checkZone(i){
	$("#cityLiId"+i+"").parent().slideToggle('fast').parent().find('.sellight').text($("#cityLiId"+i+"").text());
	var cityId=$("#cityLiId"+i+"").val();
	$.ajax({
        url: '/playerDate/querySchoolByCityId.yson',
        type: 'post',
        dataType: "json",
        data: {cityId: cityId},
        success: function (data) {
            var schoolSelect = "";
            $(data).each(function (i, obj) {
            	schoolSelect +="<li id='schoolLiId"+i+"' onclick='checkTeam("+i+")' " +
                		     "onmousemove='mouseMoveCity("+i+")' onmouseout='mouseOutCity("+i+")' " +
                		     "value=" + obj.id + ">" + obj.name + "</li>";
            	
            	$('#school_sel').attr('value','');
                $('#school_sel').text('请选择');
                $('#team_sel').attr('value','');
                $('#team_sel').text('请选择');
            });
            $("#schoolUi").empty().append(schoolSelect);
            $('#city_sel').attr('value',cityId);
        }
    });
}

function checkTeam(i){
	$("#schoolLiId"+i+"").parent().slideToggle('fast').parent().find('.sellight').text($("#schoolLiId"+i+"").text());
	var schoolLiId=$("#schoolLiId"+i+"").val();
	$.ajax({
        url: '/playerDate/queryTeamBySchoolId.yson',
        type: 'post',
        dataType: "json",
        data: {schoolId: schoolLiId},
        success: function (data) {
            var teamSelect = "";
            $(data).each(function (i, obj) {
            	teamSelect +="<li id='teamLiId"+i+"' onclick='checkPlayer("+i+")' " +
                		     "onmousemove='mouseMoveTeam("+i+")' onmouseout='mouseOutTeam("+i+")' " +
                		     "value=" + obj.id + ">" + obj.name + "</li>";
            	
            	$('#team_sel').attr('value','');
                $('#team_sel').text('请选择');
            });
            $("#teamUi").empty().append(teamSelect);
            $('#school_sel').attr('value',schoolLiId);
        }
    });
	
}


function checkPlayer(i){
	$("#teamLiId"+i+"").parent().slideToggle('fast').parent().find('.sellight').text($("#teamLiId"+i+"").text());
	teamId=$("#teamLiId"+i+"").val();
	$('#team_sel').attr('value',teamId);
	//window.location.href = "/playerDate/personalDataList.html?teamLiId="+teamLiId;
}



function mouseMoveZone(i){
	$("#cityLiId"+i+"").addClass('hovon');
}
	
function mouseOutZone(i){
	$("#cityLiId"+i+"").removeClass('hovon');
}

function mouseMoveCity(i){
	$("#schoolLiId"+i+"").addClass('hovon');
}

function mouseOutCity(i){
	$("#schoolLiId"+i+"").removeClass('hovon');
}

function mouseMoveTeam(i){
	$("#teamLiId"+i+"").addClass('hovon');
}

function mouseOutTeam(i){
	$("#teamLiId"+i+"").removeClass('hovon');
}


